<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('简历库基本信息') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('姓名')" prop="name">
        <el-input
          v-model="queryParams.name"
          :placeholder="$t('姓名')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('年龄')" prop="age">
        <el-input
          v-model="queryParams.age"
          :placeholder="$t('年龄')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['oa:resume:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['oa:resume:import']"
          type="info"
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
        >{{ $t('上传简历') }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="resumeBaseList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('姓名')" align="center" prop="name" min-width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{path:'/oa/resume/resumeBaseHome',query:{resumeId:scope.row.id,menuPath: menuKey}}"
            class="link_a"
          >{{ scope.row.name }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('性别')" align="center" prop="gender" min-width="60" show-overflow-tooltip />
      <el-table-column :label="$t('年龄')" align="center" prop="age" min-width="60" show-overflow-tooltip />
      <el-table-column :label="$t('电话号码')" align="center" prop="phone" min-width="140" show-overflow-tooltip />
      <el-table-column :label="$t('政治面貌')" align="center" prop="politStatus" min-width="130" show-overflow-tooltip />
      <el-table-column :label="$t('参加工作时间')" align="center" prop="workStartTime" min-width="130" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.workStartTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('毕业学校')" align="center" prop="college" min-width="150" show-overflow-tooltip />
      <el-table-column :label="$t('毕业学校类型')" align="center" prop="collegeType" min-width="100" show-overflow-tooltip :formatter="collegeTypeFormat" />
      <el-table-column :label="$t('毕业院系')" align="center" prop="collegeDept" min-width="120" show-overflow-tooltip />
      <el-table-column :label="$t('所学专业')" align="center" prop="major" min-width="150" show-overflow-tooltip />
      <el-table-column :label="$t('学历')" align="center" prop="degree" min-width="80" show-overflow-tooltip />
      <el-table-column :label="$t('是否统招')" align="center" prop="recruit" min-width="150" show-overflow-tooltip />
      <el-table-column :label="$t('期望工作')" align="center" prop="expectJob" min-width="120" show-overflow-tooltip />
      <el-table-column fixed="right" :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['oa:resume:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-hasPermi="['oa:resume:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改简历库基本信息对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <resumeBaseForm ref="resumeBaseForm" />
    </el-dialog>

    <!-- 导入 -->
    <el-dialog :title="$t('简历解析')" :visible.sync="upload.open" width="400px" :close-on-click-modal="false" :lock-scroll="false">
      <el-upload
        ref="upload"
        :limit="1"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload" />
        <div class="el-upload__text">
          {{ $t('将文件拖到此处，或') }}
          <em>{{ $t('上传') }}</em>
        </div>
        <!--        <div slot="tip" class="el-upload__tip">-->
        <!--          <el-checkbox v-model="upload.updateSupport" /> {{ $t('是否更新已经存在的数据') }}-->
        <!--        </div>-->
        <!--        <div slot="tip" class="el-upload__tip" style="color:red">-->
        <!--          {{ $t('提示：仅允许导入“xls”或“xlsx”格式文件！') }}-->
        <!--          <el-link type="primary" style="font-size:12px" @click="fetchTemplate">-->
        <!--            {{ $t('下载模板') }}-->
        <!--          </el-link>-->
        <!--        </div>-->
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button @click="upload.open = false">{{ $t("取消") }}</el-button>
        <el-button type="primary" @click="submitFileForm">{{ $t("确定") }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listResumeBase, delResumeBase } from '@/api/oa/resume/resumeBase'
import resumeBaseForm from './resumeBaseForm.vue'
import { getToken } from '@/utils/auth'
export default {
    components: {
        resumeBaseForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 简历库基本信息表格数据
          resumeBaseList: [],
          // 毕业院校类型
          collegeTypeOptions: [],
          // 弹出层标题
          title: '简历库基本信息',
          // 是否显示弹出层
          formOpen: false,
          menuKey: '',
          // 查询参数
          queryParams: {
              name: undefined,
              age: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {},
          // 用户导入参数
          upload: {
            // 是否显示弹出层（用户导入）
            open: false,
            // 弹出层标题（用户导入）
            title: '',
            // 是否禁用上传
            isUploading: false,
            // 是否更新已经存在的用户数据
            updateSupport: 0,
            // 设置上传的请求头部
            headers: { Authorization: 'Bearer ' + getToken() },
            // 上传的地址
            url: process.env.VUE_APP_BASE_API + '/resume/resumeBase/parserResume'
          }
      }
  },
  watch: {
    '$route': {
      handler(val) {
        this.menuKey = val.query.menuKey
      },
      deep: true,
      immediate: true
    }
  },
  created() {
      // 毕业院校类型
      this.getDicts('college_type').then(response => {
        this.collegeTypeOptions = response.data
      })
      this.getList()
  },
  methods: {
    /** 查询简历库基本信息列表 */
    getList() {
        this.loading = true
        debugger
        listResumeBase(this.queryParams).then(response => {
            this.resumeBaseList = response.rows
            this.total = response.total
            this.loading = false
        })
    },
    collegeTypeFormat(row) {
      return this.selectDictLabel(this.collegeTypeOptions, row.collegeType)
    },
    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            name: undefined,
            gender: undefined,
            age: undefined,
            maritalStatus: '0',
            birthday: undefined,
            email: undefined,
            phone: undefined,
            qq: undefined,
            weixin: undefined,
            hukouAddress: undefined,
            hometownAddress: undefined,
            idCard: undefined,
            race: undefined,
            nationality: undefined,
            politStatus: '0',
            languages: undefined,
            englishLevel: undefined,
            computerLevel: undefined,
            blog: undefined,
            workYear: undefined,
            workStartTime: undefined,
            workPosition: undefined,
            workCompany: undefined,
            workIndustry: undefined,
            workStatus: '0',
            workSalary: undefined,
            workLocation: undefined,
            workJobNature: undefined,
            gradTime: undefined,
            college: undefined,
            collegeType: undefined,
            collegeDept: undefined,
            major: undefined,
            degree: undefined,
            recruit: undefined,
            city: undefined,
            livingAddress: undefined,
            expectJob: undefined,
            expectCpy: undefined,
            expectSalary: undefined,
            expectIndustry: undefined,
            expectTime: undefined,
            expectJnature: undefined,
            expectJstatus: '0',
            expectJlocation: undefined,
            remark: undefined,
            createBy: undefined,
            updateBy: undefined,
            createTime: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.resumeBaseForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.resumeBaseForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delResumeBase(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    },
    handleImport() {
      this.upload.title = this.$t('导入')
      this.upload.open = true
    },
    // 文件上传中处理
    handleFileUploadProgress() {
      this.upload.isUploading = true
    },
    // 文件上传成功处理
    handleFileSuccess(response) {
      this.upload.open = false
      this.upload.isUploading = false
      this.$refs.upload.clearFiles()
      this.$alert(response.data.message, this.$t('导入结果'), { dangerouslyUseHTMLString: true })
      this.getList()
    },
    // 下载模板
    // fetchTemplate() {
    //   var href1 = window.location.href
    //   var href2 = this.$route.path
    //   var url = href1.substring(0, href1.indexOf(href2))
    //   window.location.href = url + '/template/人员管理导入模板.xlsx'
    // },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit()
    }
  }
}
</script>
